home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 37 / CD Expert nº 37.iso / LastCall / lastcall.exe / stuff / lastcall.dxr / 00012_Bar Spot Manager.ls < prev    next >
Encoding:
Text File  |  2000-03-27  |  14.6 KB  |  543 lines

  1. property pBarSpots, pNumberSpots, pCharList, pPurgatoryList, pMaxInPurgatory, pPukatoryList, pMaxInPukatory, pArbusExileList, pActiveSlot, pGlassMask, pGlassIce, pGlassCheat
  2. global gGameLevel, gBarGlassSprites
  3.  
  4. on new me
  5.   global gImplementedCharacters, gDemoVersion
  6.   pCharList = []
  7.   repeat with Y = 1 to count(gImplementedCharacters)
  8.     add(pCharList, getPropAt(gImplementedCharacters, Y))
  9.   end repeat
  10.   pPurgatoryList = []
  11.   pPukatoryList = []
  12.   pArbusExileList = []
  13.   if gDemoVersion then
  14.     pMaxInPurgatory = 1
  15.     pMaxInPukatory = 1
  16.   else
  17.     pMaxInPurgatory = 3
  18.     pMaxInPukatory = 2
  19.   end if
  20.   pBarSpots = []
  21.   pBarSprites = gBarGlassSprites
  22.   pNumberSpots = count(pBarSprites)
  23.   repeat with X = 1 to pNumberSpots
  24.     add(pBarSpots, [#charCode: #none, #glassType: #none, #glassMemberName: EMPTY, #xCoord: 130 + ((X - 1) * 180), #sprite: pBarSprites[X], #posOffset: 0])
  25.   end repeat
  26.   pGlassMask = 1
  27.   pGlassCheat = 2
  28.   pGlassIce = -1
  29.   return me
  30. end
  31.  
  32. on mInitialize
  33. end
  34.  
  35. on mGetNumBarSlots
  36.   return pNumberSpots
  37. end
  38.  
  39. on getClosestOpenSpot me, xLoc
  40.   barSlot = 0
  41.   proximity = the maxinteger
  42.   repeat with X = 1 to count(pBarSpots)
  43.     if not barSpotIsFree(me, X) then
  44.       thisSpot = pBarSpots[X]
  45.       if abs(xLoc - thisSpot[#xCoord]) < proximity then
  46.         proximity = abs(xLoc - thisSpot[#xCoord])
  47.         barSlot = X
  48.       end if
  49.     end if
  50.   end repeat
  51.   if getBarTopGlass(me, barSlot) = #none then
  52.     return [#closest: barSlot, #open: 1]
  53.   else
  54.     return [#closest: barSlot, #open: 0]
  55.   end if
  56. end
  57.  
  58. on barSpotAllowed me, barSlot
  59.   global gImplementedCharacters
  60.   barSlotOK = 1
  61.   repeat with X = 1 to count(pBarSpots)
  62.     if barSpotIsFree(me, X) then
  63.       next repeat
  64.     end if
  65.     checkAgainst = pBarSpots[X][#charCode]
  66.     if voidp(checkAgainst) then
  67.       debugAlert("VERY wrong checkAgainst value" && checkAgainst && X && count(gImplementedCharacters))
  68.       next repeat
  69.     else
  70.       extantCharInfo = gImplementedCharacters[checkAgainst]
  71.       if voidp(extantCharInfo) then
  72.         debugAlert("VERY wrong extantCharInfo or checkAgainst" && checkAgainst && X && count(gImplementedCharacters))
  73.         next repeat
  74.       end if
  75.     end if
  76.     case X of
  77.       1:
  78.         barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P1F)
  79.       2:
  80.         barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P2F)
  81.       3:
  82.         barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P3F)
  83.     end case
  84.     if not barSlotOK then
  85.       exit repeat
  86.     end if
  87.   end repeat
  88.   return barSlotOK
  89. end
  90.  
  91. on spotIsOkay me, charToCheck, disallowMe, excludesThese
  92.   repeat with X in charToCheck[excludesThese]
  93.     if X = disallowMe then
  94.       return 0
  95.     end if
  96.   end repeat
  97.   return 1
  98. end
  99.  
  100. on getOpenBarSeat me
  101.   global gGameLevel
  102.   openBarSeats = []
  103.   repeat with X = 1 to count(pBarSpots)
  104.     if barSpotIsFree(me, X) then
  105.       if barSpotAllowed(me, X) or inTestMode() then
  106.         add(openBarSeats, X)
  107.       end if
  108.     end if
  109.   end repeat
  110.   if count(openBarSeats) = 0 then
  111.     return 0
  112.   else
  113.     if gGameLevel > 1 then
  114.       if count(openBarSeats) = 3 then
  115.         return 2
  116.       else
  117.         if count(openBarSeats) = 2 then
  118.           if (openBarSeats[1] = 1) and (openBarSeats[2] = 2) then
  119.             return 1
  120.           else
  121.             if (openBarSeats[1] = 2) and (openBarSeats[2] = 3) then
  122.               return 3
  123.             else
  124.               return randomFromList(openBarSeats)
  125.             end if
  126.           end if
  127.         else
  128.           return randomFromList(openBarSeats)
  129.         end if
  130.       end if
  131.     else
  132.       return randomFromList(openBarSeats)
  133.     end if
  134.   end if
  135. end
  136.  
  137. on setActiveSlot me, newSlot, nextOne
  138.   if nextOne then
  139.     newSlot = findNExtOccupiedSlot(me)
  140.   end if
  141.   if newSlot = 0 then
  142.     newSlot = findNExtOccupiedSlot(me)
  143.   else
  144.     if barSpotIsFree(me, newSlot) then
  145.       alertBeep()
  146.       exit
  147.     end if
  148.   end if
  149.   if newSlot then
  150.     if pActiveSlot <> newSlot then
  151.       pActiveSlot = newSlot
  152.       refreshRecipes(pActiveSlot)
  153.     end if
  154.   end if
  155.   updateLaserPointer()
  156. end
  157.  
  158. on findNExtOccupiedSlot me, startingAt
  159.   global debug
  160.   if voidp(startingAt) then
  161.     startingAt = getActiveSlot(me)
  162.   end if
  163.   startingAt = startingAt + 1
  164.   if startingAt > 3 then
  165.     startingAt = 1
  166.   end if
  167.   if debug then
  168.     put "Finding next occupied slot starting at" && startingAt
  169.   end if
  170.   repeat with X = startingAt to count(pBarSpots)
  171.     if not barSpotIsFree(me, X) then
  172.       return X
  173.     end if
  174.   end repeat
  175.   repeat with X = 1 to startingAt
  176.     if not barSpotIsFree(me, X) then
  177.       return X
  178.     end if
  179.   end repeat
  180.   return 0
  181. end
  182.  
  183. on getActiveSlot me
  184.   if voidp(pActiveSlot) or (pActiveSlot = 0) then
  185.     pActiveSlot = findNExtOccupiedSlot(me, 1)
  186.     updateLaserPointer()
  187.     refreshRecipes(pActiveSlot)
  188.   else
  189.     if barSpotIsFree(me, pActiveSlot) then
  190.       pActiveSlot = findNExtOccupiedSlot(me, 1)
  191.       updateLaserPointer()
  192.       refreshRecipes(pActiveSlot)
  193.     end if
  194.   end if
  195.   return pActiveSlot
  196. end
  197.  
  198. on getRandomCharacter me, fillThisSeat
  199.   global pForce, gImplementedCharacters, gGameLevel, debug, gCharChildren, gDemoVersion
  200.   if not voidp(pForce) then
  201.     return pForce
  202.   end if
  203.   newCharOK = 0
  204.   noEasierThanCharacter = 1
  205.   charactersRemaining = duplicate(pCharList)
  206.   specialChars = []
  207.   repeat with X = 1 to count(charactersRemaining)
  208.     specialCharInfo = gImplementedCharacters[charactersRemaining[X]]
  209.     if specialCharInfo[#MINLEVEL] > gGameLevel then
  210.       next repeat
  211.     end if
  212.     case fillThisSeat of
  213.       1:
  214.         if (specialCharInfo[#P1A] <> 0) and count(specialCharInfo[#P1F]) then
  215.           add(specialChars, charactersRemaining[X])
  216.         end if
  217.       2:
  218.         if (specialCharInfo[#P2A] <> 0) and count(specialCharInfo[#P2F]) then
  219.           add(specialChars, charactersRemaining[X])
  220.         end if
  221.       3:
  222.         if (specialCharInfo[#P3A] <> 0) and count(specialCharInfo[#P3F]) then
  223.           add(specialChars, charactersRemaining[X])
  224.         end if
  225.     end case
  226.   end repeat
  227.   tixFreq = currentLevel(#TIXINFREQ)
  228.   ticketedChars = []
  229.   if tixFreq > 0 then
  230.     repeat with z = 1 to count(charactersRemaining)
  231.       if gCharChildren[z].pDrinkTicket > 0 then
  232.         add(ticketedChars, getPropAt(gCharChildren, z))
  233.       end if
  234.     end repeat
  235.   end if
  236.   repeat while not newCharOK
  237.     if count(ticketedChars) and (random(tixFreq) = 1) then
  238.       if debug then
  239.         put "Picking a ticketed characters" && ticketedChars
  240.       end if
  241.       thisIndex = random(count(ticketedChars))
  242.       thisOne = ticketedChars[thisIndex]
  243.     else
  244.       if (gGameLevel > 1) and count(specialChars) and (random(4) = 1) then
  245.         thisIndex = random(count(specialChars))
  246.         thisOne = specialChars[thisIndex]
  247.       else
  248.         thisIndex = random(count(charactersRemaining))
  249.         thisOne = charactersRemaining[thisIndex]
  250.       end if
  251.     end if
  252.     chosenCharInfo = gImplementedCharacters[thisOne]
  253.     if count(charactersRemaining) = 1 then
  254.       if numberAtBar(me) > 0 then
  255.         return VOID
  256.       else
  257.         if debug then
  258.           put "Accepted out of desperation" && thisOne
  259.         end if
  260.         return thisOne
  261.       end if
  262.     end if
  263.     newCharOK = 1
  264.     case fillThisSeat of
  265.       1:
  266.         newCharOK = checkExclusions(me, chosenCharInfo, #P1A, #P1F)
  267.         customPosCheck = #P1A
  268.       2:
  269.         newCharOK = checkExclusions(me, chosenCharInfo, #P2A, #P2F)
  270.         customPosCheck = #P2A
  271.       3:
  272.         newCharOK = checkExclusions(me, chosenCharInfo, #P3A, #P3F)
  273.         customPosCheck = #P3A
  274.     end case
  275.     if newCharOK then
  276.       if chosenCharInfo[customPosCheck] = 0 then
  277.         if debug then
  278.           put "This should never happen. We just found out this position is okay. So it shouldn't be zero."
  279.         end if
  280.         newCharOK = 0
  281.         posOffset = 0
  282.       else
  283.         if chosenCharInfo[customPosCheck] = 1 then
  284.           posOffset = 0
  285.         else
  286.           posOffset = chosenCharInfo[customPosCheck]
  287.         end if
  288.       end if
  289.       setBarPositionOffset(me, fillThisSeat, posOffset)
  290.     end if
  291.     if (chosenCharInfo[#MINLEVEL] > gGameLevel) and not inRecipeMode() then
  292.       if not gDemoVersion then
  293.         if debug then
  294.           put "Excluded for gameLevel" && thisOne && gGameLevel && chosenCharInfo[#MINLEVEL]
  295.         end if
  296.         newCharOK = 0
  297.       end if
  298.     end if
  299.     if chosenCharInfo[#MINLEVEL] < noEasierThanCharacter then
  300.       if debug then
  301.         debugAlert("Excluded for too low a gameLevel" && thisOne && gGameLevel && chosenCharInfo[#MINLEVEL])
  302.       end if
  303.       newCharOK = 0
  304.     end if
  305.     repeat with X = 1 to count(pBarSpots)
  306.       if barSpotIsFree(me, X) then
  307.         next repeat
  308.       else
  309.         checkAgainst = pBarSpots[X][#charCode]
  310.       end if
  311.       if checkAgainst = thisOne then
  312.         if debug then
  313.           put "Excluded for duplication" && thisOne
  314.         end if
  315.         newCharOK = 0
  316.         exit repeat
  317.         next repeat
  318.       end if
  319.       if getOne(gImplementedCharacters[checkAgainst][#EXCLUDECHAR], thisOne) then
  320.         if debug then
  321.           put "Excluded for conflict by character" && thisOne && gImplementedCharacters[checkAgainst][#EXCLUDECHAR]
  322.         end if
  323.         newCharOK = 0
  324.         exit repeat
  325.       end if
  326.     end repeat
  327.     if gCharChildren[thisOne].pBouncedPermanently then
  328.       if debug then
  329.         put "Excluded for permanent bouncing" && thisOne
  330.       end if
  331.       newCharOK = 0
  332.     end if
  333.     if getOne(pArbusExileList, thisOne) then
  334.       if debug then
  335.         put "Excluded for bouncing this round (arbusExile)" && thisOne
  336.       end if
  337.       newCharOK = 0
  338.     end if
  339.     if getOne(pPurgatoryList, thisOne) then
  340.       if debug then
  341.         put "Excluded for recent visit (purgatory)" && thisOne
  342.       end if
  343.       newCharOK = 0
  344.     end if
  345.     if getOne(pPukatoryList, thisOne) then
  346.       if debug then
  347.         put "Excluded for pukatory" && thisOne
  348.       end if
  349.       newCharOK = 0
  350.     end if
  351.     if getOne(specialChars, thisOne) > 0 then
  352.       deleteAt(specialChars, getOne(specialChars, thisOne))
  353.     end if
  354.     if getOne(ticketedChars, thisOne) > 0 then
  355.       deleteAt(ticketedChars, getOne(ticketedChars, thisOne))
  356.     end if
  357.     if getOne(charactersRemaining, thisOne) > 0 then
  358.       deleteAt(charactersRemaining, getOne(charactersRemaining, thisOne))
  359.     end if
  360.     if debug then
  361.       put "Rejected all but the last one printed" && thisOne
  362.     end if
  363.   end repeat
  364.   if debug then
  365.     put "New character enters:" && thisOne
  366.   end if
  367.   return thisOne
  368. end
  369.  
  370. on checkExclusions me, charToCheck, allowed, excluded
  371.   if charToCheck[allowed] = 0 then
  372.     return 0
  373.   end if
  374.   repeat with X in charToCheck[excluded]
  375.     if not barSpotIsFree(me, X) then
  376.       return 0
  377.     end if
  378.   end repeat
  379.   repeat with X in charToCheck[excluded]
  380.     if not barSpotIsFree(me, X) then
  381.       return 0
  382.     end if
  383.   end repeat
  384.   return 1
  385. end
  386.  
  387. on maxAutoAtBar me
  388.   maxAutoPatrons = min(2, currentLevel(#MaxPatrons))
  389.   if numberAtBar(me) >= maxAutoPatrons then
  390.     return 1
  391.   else
  392.     return 0
  393.   end if
  394. end
  395.  
  396. on maxAtBar me
  397.   MaxPatrons = currentLevel(#MaxPatrons)
  398.   if inTestMode() then
  399.     MaxPatrons = 3
  400.   end if
  401.   if numberAtBar(me) >= MaxPatrons then
  402.     return 1
  403.   else
  404.     return 0
  405.   end if
  406. end
  407.  
  408. on numberAtBar me
  409.   countMe = 0
  410.   repeat with X = 1 to count(pBarSpots)
  411.     if not barSpotIsFree(me, X) then
  412.       countMe = countMe + 1
  413.     end if
  414.   end repeat
  415.   return countMe
  416. end
  417.  
  418. on barSpotIsFree me, thisSpot
  419.   return pBarSpots[thisSpot][#charCode] = #none
  420. end
  421.  
  422. on addToPukatory me, barSlot
  423.   add(pPukatoryList, pBarSpots[barSlot][#charCode])
  424.   if count(pPukatoryList) > pMaxInPukatory then
  425.     deleteAt(pPukatoryList, 1)
  426.   end if
  427. end
  428.  
  429. on setBarTopCharacter me, barSlot, charCode
  430.   if count(pPurgatoryList) > pMaxInPurgatory then
  431.     deleteAt(pPurgatoryList, 1)
  432.   end if
  433.   pBarSpots[barSlot][#charCode] = charCode
  434. end
  435.  
  436. on removeBarTopCharacter me, barSlot
  437.   global gLastVessel
  438.   add(pPurgatoryList, pBarSpots[barSlot][#charCode])
  439.   pBarSpots[barSlot][#charCode] = #none
  440.   if count(pPurgatoryList) > pMaxInPurgatory then
  441.     deleteAt(pPurgatoryList, 1)
  442.   end if
  443.   removeBarTopGlass(me, barSlot)
  444.   barGlass = getActiveGlass()
  445.   if barGlass = 0 then
  446.     setPourClockText(" Drink Contents Shown Here")
  447.     gLastVessel = 0
  448.   else
  449.     barGlass.pContentString = EMPTY
  450.     gLastVessel = sprite(barGlass).pMyBarSlot
  451.     newString = buildVesselContentList(barGlass, barGlass.pGlassType, " The Glass is Empty")
  452.     setPourClockText(newString)
  453.   end if
  454. end
  455.  
  456. on removeBarTopGlass me, barSlot
  457.   pBarSpots[barSlot][#glassType] = #none
  458.   pBarSpots[barSlot][#glassMemberName] = EMPTY
  459.   sendSprite(barSlotToGlassSprite(me, barSlot), #mRemoveDrink)
  460. end
  461.  
  462. on barSlotToGlassSprite me, barSlot
  463.   if (barSlot < 1) or (barSlot > count(pBarSpots)) then
  464.     return VOID
  465.   else
  466.     return sprite(pBarSpots[barSlot][#sprite])
  467.   end if
  468. end
  469.  
  470. on setBarPositionOffset me, barSlot, newOffset
  471.   if (barSlot > 0) and (barSlot <= count(pBarSpots)) then
  472.     pBarSpots[barSlot][#posOffset] = newOffset
  473.   end if
  474. end
  475.  
  476. on getBarPositionOffset me, barSlot
  477.   if (barSlot < 1) or (barSlot > count(pBarSpots)) then
  478.     return 0
  479.   else
  480.     return pBarSpots[barSlot][#posOffset]
  481.   end if
  482. end
  483.  
  484. on getBarTopGlass me, barSlot
  485.   if (barSlot < 1) or (barSlot > count(pBarSpots)) then
  486.     return #none
  487.   else
  488.     return pBarSpots[barSlot][#glassType]
  489.   end if
  490. end
  491.  
  492. on getBarTopGlassMember me, barSlot
  493.   if (barSlot < 1) or (barSlot > count(pBarSpots)) then
  494.     return EMPTY
  495.   else
  496.     return pBarSpots[barSlot][#glassMemberName]
  497.   end if
  498. end
  499.  
  500. on mDrinkOffset me, barSlot, glassType
  501.   global gImplementedCharacters
  502.   charCode = pBarSpots[barSlot][#charCode]
  503.   if charCode = #none then
  504.     glassPosition = point(0, 0)
  505.   else
  506.     theseGlassXYs = gImplementedCharacters[charCode][#glassXY]
  507.     glassPosition = theseGlassXYs[symbol(glassPrefix(glassType))]
  508.     if voidp(glassPosition) then
  509.       glassPosition = theseGlassXYs[#def]
  510.     end if
  511.   end if
  512.   return point(glassPosition.locH + getBarPositionOffset(me, barSlot), glassPosition.locV)
  513. end
  514.  
  515. on setBarTopGlass me, barSlot, newMember, glassType, keepOldMaskAndIce, transferContents, newGarnish, oldIceAmount
  516.   newLoc = point(pBarSpots[barSlot][#xCoord], 251) + mDrinkOffset(me, barSlot, glassType)
  517.   glassSprite = barSlotToGlassSprite(me, barSlot)
  518.   pBarSpots[barSlot][#glassType] = glassType
  519.   pBarSpots[barSlot][#glassMemberName] = newMember
  520.   sendSprite(glassSprite, #mPlaceDrink, newMember, newLoc, glassType, keepOldMaskAndIce)
  521.   sendSprite(glassSprite, #mUpdateContents, glassType, transferContents, newGarnish, oldIceAmount)
  522.   setActiveSlot(me, barSlot)
  523. end
  524.  
  525. on showBarGlass me, barSlot, flag
  526.   glassSprite = barSlotToGlassSprite(me, barSlot)
  527.   if flag then
  528.     sendSprite(glassSprite, #mShowDrink)
  529.   else
  530.     sendSprite(glassSprite, #mHideDrink)
  531.   end if
  532. end
  533.  
  534. on mOverItem me, bottleSprite, spoutLoc
  535.   repeat with X in pBarSpots
  536.     Y = pBarSpots[#sprite]
  537.     if sendSprite(Y, #mOverItem, bottleSprite, spoutLoc) then
  538.       return 1
  539.     end if
  540.   end repeat
  541.   return 0
  542. end
  543.